package com.lichao.tools;

/**
 * @author: li chao
 * @Desc:
 * @create: 2024-10-22 09:47
 **/

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.io.File;
import java.io.IOException;

public class XmlToJsonConverter {
    public static void main(String[] args) {
        try {
            XmlMapper xmlMapper = new XmlMapper();
            ObjectMapper jsonMapper = new ObjectMapper();

            // 读取XML文件
            File xmlFile = new File("D:\\data\\idea\\learning-space\\Java-EE\\pom.xml");
            JsonNode xmlTree = xmlMapper.readTree(xmlFile);

            // 转换为JSON
            String json = jsonMapper.writeValueAsString(xmlTree);

            // 输出JSON
            System.out.println(json);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}